#include "DialServicesSDK.h"
#include <unistd.h>
#include <cstring>
using namespace std;

int main(int argc, char *argv[])
{
	string servName, clientName;
	CDialClientAPI dialClientAPI;
	int 	iRet;
	char 	request[255];
	int 	requestLen;
	char 	responses[255];
	int 	responsesLen;
	tagRespInfo  tRespInfo;

	
	if (argc < 3)
	{
		printf ("print enter server and client name , exit .\n");
		return -1;
	}
	
	servName = argv[1];
	clientName	 = argv[2];

    iRet = dialClientAPI.ClientStart(clientName);
	if (iRet != CN_DIALERRNO_SUCCESS)
	{
		printf("dialServicerAPI.ClientStart failed, iRet=%d\n", iRet);
		return -1;
	}

	sleep(3);
	
    responsesLen = 0;
	requestLen = 0;
	strcpy(request, "ping");
	requestLen =strlen(request);

	iRet = dialClientAPI.Request(servName,request,requestLen);
	if (iRet == CN_DIALERRNO_SUCCESS)
	{
		printf("dialClientAPI.Calling ping success ! \n");
	}
	else
	{
		printf("dialClientAPI.Calling ping, failed, iRet=%d\n", iRet);
		return -1;
	}
	
	iRet = dialClientAPI.WaitResponse(&tRespInfo,5000);
	if (iRet != CN_DIALERRNO_SUCCESS)
	{
		printf("dialClientAPI.WaitResponse , failed, iRet=%d\n", iRet);
		return -1;
	}
	printf("dialClientAPI.WaitResponse success, servName=%s, invokeID=%d, respLen=%d\n"
		, tRespInfo.servName, tRespInfo.invokeID, tRespInfo.respLen);
	
	dialClientAPI.FreeRespInfo(&tRespInfo);
    return 1;
}
